import 'package:flutter/material.dart';
import 'package:flutterproject/config/route_config.dart';
import 'package:flutterproject/util/sp_util/shared_preferences.dart';
import 'package:flutterproject/util/sp_util/sp_key.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:get/get.dart';

class SplashPage extends StatefulWidget {
  @override
  SplashPageState createState() => SplashPageState();
}

class SplashPageState extends State<SplashPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: Get.width,
      height: Get.height,
      color: Colors.white,
      child: ImageCommon(
        "/image/splash",
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    if (SPUtils().getString(SPKey.token) == "") {
      Future.delayed(const Duration(seconds: 2),
          () => Get.offAndToNamed(RouteName.loginPage.toString()));
    } else {
      Future.delayed(const Duration(seconds: 2),
          () => Get.offAndToNamed(RouteName.homePage.toString()));
    }
  }
}
